package com.guinea.generator;

import com.guinea.core.utils.StringUtils;

public class MappingManyToMany {
	String name;

	String className;

	String refProperty;

	String table;

	String keyColumn;

	String refColumn;

	String inverse;

	MappingClass parent;

	public MappingManyToMany(String name, String className, String refProperty,
			String table, String keyColumn, String refColumn, String inverse) {
		super();
		this.name = StringUtils.uncapitalize(name);
		this.className = StringUtils.capitalize(className);
		this.refProperty = StringUtils.uncapitalize(refProperty);
		this.inverse = StringUtils.defaultString(inverse, "false");
		this.table = table == null ? null : table.toUpperCase();
		this.keyColumn = keyColumn == null ? null : keyColumn.toUpperCase();
		this.refColumn = refColumn == null ? null : refColumn.toUpperCase();
	}

	public String getClassName() {
		return className;
	}

	public void setClassName(String className) {
		this.className = className;
	}

	public String getInverse() {
		return inverse;
	}

	public void setInverse(String inverse) {
		this.inverse = inverse;
	}

	public String getKeyColumn() {
		return keyColumn;
	}

	public void setKeyColumn(String keyColumn) {
		this.keyColumn = keyColumn;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getRefColumn() {
		return refColumn;
	}

	public void setRefColumn(String refColumn) {
		this.refColumn = refColumn;
	}

	public String getTable() {
		return table;
	}

	public void setTable(String table) {
		this.table = table;
	}

	public String getRefProperty() {
		return refProperty;
	}

	public void setRefProperty(String refProperty) {
		this.refProperty = refProperty;
	}

	public MappingClass getParent() {
		return parent;
	}

	public void setParent(MappingClass parent) {
		this.parent = parent;
		String parentClassName = getParent().getName();
		if (this.table == null) {
			String s = this.inverse == "false" ? parentClassName
					+ this.className : this.className + parentClassName;
			this.table = ConfigUtils.camelToTable(s, getParent().prefix);
		}
		if (this.keyColumn == null)
			this.keyColumn = ConfigUtils.camelToTable(parentClassName) + "_ID";
		if (this.refColumn == null)
			this.refColumn = ConfigUtils.camelToTable(this.className) + "_ID";
	}

}
